<?php
/*******************************************************************************

    FinalsClub.org is a platform for students and faculty to collaborate
    and share their knowledge with the world.

    Copyright (C) 2009  Andrew Magliozzi
 
    This file is a part of FinalsClub.org.

    FinalsClub.org is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
    To contact FinalsClub.org, send an email to info@finalsclub.org, or
    send mail to Finals Club, c/o Veritas Tutors, 1132 Massachusetts Avenue,
    Cambridge, MA 02138.

*******************************************************************************/

	/*
	 * 
	 */
use_helper('User');

//==========detail view funcitons =====================//
	function renderItemDetail($item) {
		
		// get the feed type
		$render_func = 'renderDetail' . ucwords($item['type']);	// the method to render the feed
		return call_user_func($render_func, $item);		// call the method
	}
	
	
	function renderDetailSummary( $item) {
		$summary = SummaryPeer::retrieveById($item['obj_id']);
		
		$icon_text = $item['category'];
		
		$icon = '<p class="icon '.$icon_text.'">'.ucwords($icon_text).'</p>';
		$title = '<h3><a href="'.url_for('summaries/show').'?id='.$summary->getId().'">'.$summary->getTitle().'</a></h3>';
		$author = '<p class="related-users"><strong>Author: </strong><a href="#">'.$summary->getAuthor().'</a></p>';
		$details = '<p>'.$summary->getText().'</p>';
		
		
		return '<li>'.$icon.$title.'<div class="details">'.$author.$details.'</div></li>';
				
	}

	
	function renderDetailFile($item) {
		$file = FilePeer::retrieveById($item['obj_id']);
		$user = new User();
		$user = UserPeer::retrieveById($file->getOwnerId());
		
		
		if($user->getId() == sfContext::getInstance()->getUser()->getId())
			$who = "You";
		else
			$who = link_to("<strong>" . $user->getFullName() . "</strong>", 'user_profiles/show?id=' . $user->getId());
		
		$icon_text = $item['category'];
		
		$icon = '<p class="icon '.$icon_text.'">'.ucwords($icon_text).'</p>';
		$title = '<h3><a href="'.$file->getAnnotateFileViewURL().'">'.$file->getName().'</a></h3>';
		$author = '<p class="related-users"><strong>Author: </strong>'.$who.'</p>';
		$details = '<p>'.$file->getDescription().'</p>';
		
		if(sfContext::getInstance()->getUser()->getId() == $file->getOwnerId())
		{
			$delete = '<p class="related-users"><a class="library-file-delete" href="'.url_for('files/delete').'?c='.$file->getCode().'&d='.$file->getAnnotateDate().'"> delete </a></p>';
		}
		else
		{
			$delete = '';
		}
		
		return '<li>'.$icon.$title.'<div class="details">'.$author.$delete.$details.'</div></li>';
	
	}
	
	
	function renderDetailBook($item) {
		$book = BookPeer::retrieveByPk($item['obj_id']);
		$user = new User();
		
		$icon_text = $item['category'];
		
		$icon = '<p class="icon '.$icon_text.'">'.ucwords($icon_text).'</p>';
		$title = '<h3><a href="'.url_for('books/showTOC').'?id='.$book->getId().'">'.$book->getTitle().'</a></h3>';
		$author = '<p class="related-users"><strong>Author: </strong>'.$book->getAuthor().'</p>';
		$details = '<p>'.$book->getSummary().'</p>';
		
		
		return '<li>'.$icon.$title.'<div class="details">'.$author.$details.'</div></li>';
	
	}
	
	
//================list view functions ==========================//
	function renderItemList($item) {
		
		// get the feed type
		$render_func = 'renderList' . ucwords($item['type']);	// the method to render the feed
		return call_user_func($render_func, $item);		// call the method
	}
	
	
	function renderListSummary( $item) {
		$summary = SummaryPeer::retrieveById($item['obj_id']);
		
		$icon_text = $item['category'];
		
		$icon = '<p class="icon '.$icon_text.'">'.ucwords($icon_text).'</p>';
		$title = '<h3><a href="'.url_for('summaries/show').'?id='.$summary->getId().'">'.$summary->getTitle().'</a></h3>';
		$author = '<p class="related-users"><strong>Author: </strong><a href="#">'.$summary->getAuthor().'</a></p>';
		$annotations ='';// '<p class="num-annotations">'.''.' annotations </p>';
		
		
		return '<li>'.$icon.'<div class="details">'.$title.$author.'</div>'.$annotations.'</li>';
						
	}

	
	function renderListFile( $item) {
		$file = FilePeer::retrieveById($item['obj_id']);
		$user = new User();
		$user = UserPeer::retrieveById($file->getOwnerId());
		
		
		
		if($user->getId() == sfContext::getInstance()->getUser()->getId())
			$who = "You";
		else
			$who = link_to("<strong>" . $user->getFullName() . "</strong>", 'user_profiles/show?id=' . $user->getId());
		
		$icon_text = $item['category'];
		
		$icon = '<p class="icon '.$icon_text.'">'.ucwords($icon_text).'</p>';
		$title = '<h3><a href="'.$file->getAnnotateFileViewURL().'">'.$file->getName().'</a></h3>';
		$author = '<p class="related-users"><strong>Author: </strong>'.$who.'</p>';
		$annotations = '';//<p class="num-annotations">'.''.' annotations </p>';
		
		if(sfContext::getInstance()->getUser()->getId() == $file->getOwnerId())
		{
			$delete = '<p class="related-users"><a class="library-file-delete" href="'.url_for('files/delete').'?c='.$file->getCode().'&d='.$file->getAnnotateDate().'">delete</a></p>';
		}
		else
		{
			$delete = '';
		}
		
		return '<li>'.$icon.'<div class="details">'.$title.$author.$delete.'</div>'.$annotations.'</li>';
		
	}
	
	
	function renderListBook( $item) {
		$book = BookPeer::retrieveByPk($item['obj_id']);
		$user = new User();
		
		$icon_text = $item['category'];
		
		$icon = '<p class="icon '.$icon_text.'">'.ucwords($icon_text).'</p>';
		$title = '<h3><a href="'.url_for('books/showTOC').'?id='.$book->getId().'">'.$book->getTitle().'</a></h3>';
		$author = '<p class="related-users"><strong>Author: </strong>'.$book->getAuthor().'</p>';
		$annotations = ''; //<p class="num-annotations">'.''.' annotations </p>';
		
	
		return '<li>'.$icon.'<div class="details">'.$title.$author.'</div>'.$annotations.'</li>';
		
	}
	
?>